import { Window } from "../../../../component/window/Window";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { Language } from "../../../../../extend/language/Language";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { BaseItem } from "../../common/BaseItem";
import { PetExploreBattleListPanel } from "./PetExploreBattleListPanel";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { SPetExploreResult } from "../../../../../Message/Public/SPetExploreResult";
import { SReward } from "../../../../../Message/Public/SReward";
import { ItemData } from "../../../resource/info/ItemData";
import { Cache } from "../../../cache/Cache";
import { PetExploreConfig } from "../../../resource/PetExploreConfig";
import { PetExploreAreaConfig } from "../../../resource/PetExploreAreaConfig";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { PetExploreConfigInfo } from "../../../resource/info/PetExploreConfigInfo";
import { PetExploreAreaInfo } from "../../../resource/info/PetExploreAreaInfo";
type int = number;
//class PetExploreSuccessWindow
    
    export  class PetExploreSuccessWindow extends Window
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._baseItemArray = [];
            this._cardItemArray = [];
            this._battlePetItemArray = [];
            this.setSize(300, 385);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc1=null;
            var loc3=null;
            super.createChildren();
            _windowBg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            _windowBg.width = 300;
            _windowBg.height = 385;
            $addChildAt(_windowBg, 0);
            this._exploreSuccess = new Object /* flash.display.Bitmap */();
            this._exploreSuccess.x = 100;
            this._exploreSuccess.y = 10;
            this.addChild(this._exploreSuccess);
            ObjCreate.createTextField(Language.getString(54521), 88, 60, 80, 20, this, new GTextFormat(FontUtil.songtiName, 14, 15788607));
            this._cnameTxt = ObjCreate.createTextField("", 155, 60, 80, 30, this, new GTextFormat(FontUtil.songtiName, 16, 65280, true));
            this._cnameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            ObjCreate.createTextField(Language.getString(54522), 15, 95, 80, 20, this, GlobalStyle.textFormat6);
            var loc2=0;
            while (loc2 < 3) 
            {
                ObjCreate.createBg(75 + loc2 * 41, 85, 38, 38, this, ImagesConst.PackItemBg);
                loc1 = new BaseItem();
                loc1.isDragAble = false;
                loc1.isDropAble = false;
                loc1.setSize(32, 32);
                loc1.x = 77 + loc2 * 41;
                loc1.y = 87;
                this.addChild(loc1);
                this._baseItemArray.push(loc1);
                ++loc2;
            }
            ObjCreate.createTextField(Language.getString(54549), 15, 160, 80, 20, this, GlobalStyle.textFormat6);
            var loc4=0;
            while (loc4 < 3) 
            {
                ObjCreate.createBg(75 + loc4 * 41, 150, 38, 38, this, ImagesConst.PackItemBg);
                loc3 = new BaseItem();
                loc3.isDragAble = false;
                loc3.isDropAble = false;
                loc3.setSize(32, 32);
                loc3.x = 77 + loc4 * 41;
                loc3.y = 152;
                this.addChild(loc3);
                this._cardItemArray.push(loc3);
                ++loc4;
            }
            ObjCreate.createTextField(Language.getString(54523), 15, 130, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._backTxt = ObjCreate.createTextField("", 230, 173, 300, 20, this, new GTextFormat(FontUtil.songtiName, 12, 15788607, true));
            this._backTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._backTxt.htmlText = Language.getString(54524);
            this._backTxt.addEventListener(flash.events.TextEvent.LINK, this.onBackHandler);
            ObjCreate.createBg(15, 200, 270, 2, this, ImagesConst.SplitLine);
            this._eLabel = ObjCreate.createTextField(Language.getString(54525), 98, 208, 60, 20, this, GlobalStyle.textFormat6);
            this._enameTxt = ObjCreate.createTextField("", 155, 208, 80, 30, this, new GTextFormat(FontUtil.songtiName, 14, 16711680, true));
            this._enameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._continueBtn = ObjCreate.createGButton(Language.getString(54526), 123, 232, 70, 26, this, "ButtonSpecial");
            this._continueBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onContinueBtnClickHandler);
            this._nextTipTxt = ObjCreate.createTextField("", 0, 210, 300, 20, this);
            this._nextTipTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            ObjCreate.createBitmap(ImagesConst.BattlePetLabel, 15, 265, this);
            ObjCreate.createTextField(Language.getString(54477), 105, 270, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            this._battleListPanel = new PetExploreBattleListPanel();
            this._battleListPanel.x = 5;
            this._battleListPanel.y = 290;
            this._battleListPanel.isSaveChange = true;
            this.addChild(this._battleListPanel);
            ObjCreate.createTextField(Language.getString(54477), 105, 270, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            ObjCreate.createTextField(Language.getString(54478), 15, 355, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280, true));
            this._gnumTxt = ObjCreate.createTextField("", 120, 355, 220, 20, this, new GTextFormat(FontUtil.songtiName, 12, 65280));
            LoaderHelp.addResCallBack(ResFileConst.petExplore, this.onBitmapLoaderHandler);
            return;
        }

        protected /* override */ updateBtnSize(): void
        {
            super.updateBtnSize();
            _closeBtn.x = this.width - _closeBtn.width;
            _closeBtn.y = 0;
            return;
        }

        public updateByPetExploreResult(arg1: SPetExploreResult): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc6=null;
            var loc7=0;
            this._exploreResult = arg1;
            var loc1=arg1.rewards;
            var loc5=0;
            while (loc5 < this._baseItemArray.length) 
            {
                loc2 = this._baseItemArray[loc5] as BaseItem;
                if (loc3 = loc1[loc5] as SReward) 
                {
                    (loc4 = new ItemData(loc3.code)).itemAmount = loc3.num;
                    loc2.itemData = loc4;
                }
                else 
                {
                    loc2.itemData = null;
                }
                ++loc5;
            }
            var loc8=0;
            while (loc8 < this._cardItemArray.length) 
            {
                loc6 = this._cardItemArray[loc8] as BaseItem;
                if ((loc7 = arg1.cards[loc8] as int) > 0) 
                {
                    loc6.itemData = new ItemData(loc7);
                }
                else 
                {
                    loc6.itemData = null;
                }
                ++loc8;
            }
            this.updateName();
            this._gnumTxt.text = Cache.instance.petExplore.getExploredNum().toString() + "/" + PetExploreConfig.instance.rbNum;
            this._battleListPanel.updateByPetUids(Cache.instance.petExplore.petExploreInfo.petUids, false);
            if (this._nextConfig) 
            {
                if (this._nextConfig.area > Cache.instance.petExplore.getExploreAreaIndex()) 
                {
                    this._nextAreaInfo = PetExploreAreaConfig.instance.getAreaConfigByArea(this._nextConfig.area);
                    this._eLabel.visible = false;
                    this._enameTxt.visible = false;
                    this._continueBtn.visible = false;
                    this._nextTipTxt.visible = true;
                    this._nextTipTxt.htmlText = Language.getStringByParam(54527, this._nextAreaInfo.name);
                    Cache.instance.petExplore.selectedConfigInfo = null;
                }
                else 
                {
                    this._eLabel.visible = true;
                    this._enameTxt.visible = true;
                    this._continueBtn.visible = true;
                    this._nextTipTxt.visible = false;
                }
            }
            else 
            {
                this._eLabel.visible = false;
                this._enameTxt.visible = false;
                this._continueBtn.visible = false;
                this._nextTipTxt.visible = true;
                this._nextTipTxt.htmlText = Language.getString(54528);
                Cache.instance.petExplore.selectedConfigInfo = null;
            }
            return;
        }

        /* internal  */onBitmapLoaderHandler(): void
        {
            this._exploreSuccess.bitmapData = GlobalClass.getBitmapData(ImagesConst.ExploreSuccess);
            return;
        }

        /* internal  */onReplayClickHandler(arg1: Object /* flash.events.Event */): void
        {
            return;
        }

        /* internal  */onContinueBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=0;
            var loc2=false;
            var loc3=false;
            if (this._nextConfig) 
            {
                loc1 = this._nextConfig.level;
                loc2 = false;
                loc3 = false;
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreStart, {"startLevel": loc1, "isAutoExplore": loc2, "isDrawRewards": loc3, "callBack": this.onStartExploreReponse}));
            }
            return;
        }

        /* internal  */onStartExploreReponse(): void
        {
            this.hide();
            Cache.instance.petExplore.selectedConfigInfo = this._nextConfig;
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreBattleWindowOpen));
            Cache.instance.petExplore.initJoinPet();
            return;
        }

        /* internal  */onBackHandler(arg1: Object /* flash.events.Event */): void
        {
            this.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreBattleWindowClose));
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetExploreOpen));
            return;
        }

        /* internal  */updateName(): void
        {
            var loc1=PetExploreConfig.instance.getExploreConfigByLevel(this._exploreResult.currentLevel);
            this._cnameTxt.text = loc1.name;
            this._nextConfig = PetExploreConfig.instance.getExploreConfigByLevel(this._exploreResult.currentLevel + 1);
            if (this._nextConfig) 
            {
                this._enameTxt.text = this._nextConfig.name;
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            return;
        }

        /* internal */ /* var */_cnameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_eLabel: Object /* flash.text.TextField */;

        /* internal */ /* var */_enameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_replayTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_continueBtn: GButton;

        /* internal */ /* var */_backTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_gnumTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_battleListPanel: PetExploreBattleListPanel;

        /* internal */ /* var */_nextTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_exploreSuccess: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_baseItemArray: Array<any>;

        /* internal */ /* var */_cardItemArray: Array<any>;

        /* internal */ /* var */_battlePetItemArray: Array<any>;

        /* internal */ /* var */_nextConfig: PetExploreConfigInfo;

        /* internal */ /* var */_nextAreaInfo: PetExploreAreaInfo;

        /* internal */ /* var */_exploreResult: SPetExploreResult;
    }
